// test_deepseek_endpoints.js - 测试不同的DeepSeek API端点
const dotenv = require('dotenv');
const path = require('path');
const axios = require('axios');

// 加载环境变量
dotenv.config({ path: path.resolve(__dirname, '.env') });

const deepSeekApiKey = process.env.DEEPSEEK_API_KEY;
const modelName = process.env.DEEPSEEK_EMBEDDING_MODEL || "deepseek-embedding";

// 测试不同的API端点
const endpoints = [
    "https://api.deepseek.com/v1/embeddings",  // 当前配置
    "https://api.deepseek.com/embeddings",     // 代码中的默认值
    "https://api.deepseek.com/v1/models/embeddings", // 可能的其他端点
];

async function testEndpoint(endpoint) {
    try {
        console.log(`测试端点: ${endpoint}`);
        const response = await axios.post(
            endpoint,
            {
                model: modelName,
                input: "测试文本"
            },
            {
                headers: {
                    "Authorization": `Bearer ${deepSeekApiKey}`,
                    "Content-Type": "application/json"
                },
                timeout: 10000
            }
        );
        
        console.log(`✓ 成功: ${endpoint} - 状态码: ${response.status}`);
        return true;
    } catch (error) {
        console.log(`✗ 失败: ${endpoint} - 错误: ${error.response?.status || error.message}`);
        return false;
    }
}

async function testAllEndpoints() {
    console.log("测试不同的DeepSeek API端点...");
    
    if (!deepSeekApiKey) {
        console.error("错误: DEEPSEEK_API_KEY 未设置");
        return;
    }
    
    for (const endpoint of endpoints) {
        await testEndpoint(endpoint);
        console.log("---");
    }
}

testAllEndpoints();